import requests
from pydantic import Field

class WeatherTool:
    city : str=Field(description='city_name')

    def __init__(self, api_key):
        self.api_key = api_key

    def run(self,city):
        city = city.split("\n")[0]
        url=f'https://api.seniverse.com/v3/weather/now.json?key={self.api_key}&location={city}&language=zh-Hans&unit=c'
        response = requests.get(url)

        if response.status_code == 200:
            data=response.json()
            weather=data['results'][0]['now']['text']
            temperature=data['results'][0]['now']['temperature']

            return f"{city}天气情况：{weather}; 温度：{temperature}°C"
        else:
            return "无法获取"
api_key='S1X5W-B1f8r-MMyb4'
weather_func=WeatherTool(api_key)
